package org.mspring.platform.dao.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.mspring.platform.dao.Page;
import org.mspring.platform.dao.hibernate.common.CriteriaQuery;
import org.mspring.platform.dao.hibernate.common.EnhancedRule;
import org.mspring.platform.dao.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author Gao Youbo
 * @since 2013年7月22日
 */
public class BaseDao implements IBaseDao {

    private DefaultHibernateTemplate hibernateTemplate;

    @Autowired
    public void setHibernateTemplate(DefaultHibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }

    protected DefaultHibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    protected JdbcTemplate getJdbcTemplate() {
        return hibernateTemplate.getJdbcTemplate();
    }

    @Override
    public List<?> list(String hql, Object... params) {
        return hibernateTemplate.list(hql, params);
    }

    @Override
    public List<?> list(Class<?> entityClass, EnhancedRule enhancedRule) {
        return hibernateTemplate.list(entityClass, enhancedRule);
    }

    @Override
    public List<?> list(CriteriaQuery criteriaQuery) {
        return hibernateTemplate.list(criteriaQuery);
    }

    @Override
    public List<?> list(QueryBuilder queryBuilder) {
        return hibernateTemplate.list(queryBuilder);
    }

    @Override
    public List<?> list(DetachedCriteria detachedCriteria) {
        return hibernateTemplate.findByCriteria(detachedCriteria);
    }

    @Override
    public List<?> list(DetachedCriteria detachedCriteria, int firstResult, int maxResults) {
        return hibernateTemplate.findByCriteria(detachedCriteria, firstResult, maxResults);
    }

    @Override
    public int executeUpdate(String hql, Object... params) {
        return hibernateTemplate.executeUpdate(hql, params);
    }

    @Override
    public void delete(Class<?> entityClass, Serializable... id) {
        hibernateTemplate.delete(entityClass, id);
    }

    @Override
    public void delete(Object entity) {
        hibernateTemplate.delete(entity);
    }

    @Override
    public void update(Object entity) {
        hibernateTemplate.update(entity);
    }

    @Override
    public <T> T get(Class<T> entityClass, Serializable id) {
        return hibernateTemplate.get(entityClass, id);
    }

    @Override
    public List<?> listAll(Class<?> entityClass) {
        return hibernateTemplate.listAll(entityClass);
    }

    @Override
    public Object getBy(Class<?> entityClass, String property, Object value) {
        return hibernateTemplate.getBy(entityClass, property, value);
    }

    @Override
    public Object uniqueResult(String hql, Object... params) {
        return hibernateTemplate.uniqueResult(hql, params);
    }

    @Override
    public Page<?> listPage(Class<?> entityClass, Page<?> page) {
        return hibernateTemplate.listPage(entityClass, page);
    }

    @Override
    public Page<?> listPage(QueryBuilder queryBuilder, Page<?> page) {
        return hibernateTemplate.listPage(queryBuilder, page);
    }

    @Override
    public Page<?> listPage(String hql, Page<?> page, Object... params) {
        return hibernateTemplate.listPage(hql, page, params);
    }

    @Override
    public Page<?> listPage(CriteriaQuery criteriaQuery, Page<?> page) {
        return hibernateTemplate.listPage(criteriaQuery, page);
    }

    @Override
    public Serializable insert(Object entity) {
        return hibernateTemplate.save(entity);
    }

    @Override
    public Object merge(Object entity) {
        return hibernateTemplate.merge(entity);
    }

    @Override
    public int count(String hql, Object... params) {
        return hibernateTemplate.count(hql, params);
    }

    @Override
    public int count(Class<?> entityClass, EnhancedRule enhancedRule) {
        return hibernateTemplate.count(entityClass, enhancedRule);
    }

}
